<template>
  <div>
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose"
      :modal-append-to-body="false"
    >
      <el-row>
        <el-col :span="12">项目名称：{{ projectName }}</el-col>
        <el-col :span="12">项目ID：{{ projectId }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="12">项目工点名称：{{ pointName }}</el-col>
        <el-col :span="12">项目工点ID：{{ pointId }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="24">考勤机SN编号：{{ machineNO }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="12">项目总人数：{{ allEmpCount }}</el-col>
        <el-col :span="12"></el-col>
      </el-row>
      <el-row>
        <el-col :span="12">工点在职人数：{{ pointEmpCount }}</el-col>
        <el-col :span="12">工点成功拉取人数：{{ downEmpCount }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="12">工点在职人脸数：{{ faceOnJobCount }}</el-col>
        <el-col :span="12">成功拉取人脸数：{{ downFaceCount }}</el-col>
      </el-row>
      <!--            <el-row>-->
      <!--              <el-col :span="12">工点在职人脸数：{{faceOnJobCount}}</el-col>-->
      <!--                <el-col :span="12"></el-col>-->
      <!--            </el-row>-->
      <el-row style="margin-top: 40px">
        <el-col :span="12" class="cmd-col">
          <el-button
            type="primary"
            icon="el-icon-user"
            class="commonBtn cmd-btn"
            @click="onRestDownEmp()"
            >重新拉取人员</el-button
          >
          <div class="cmd-margin">
            <i class="el-icon-refresh cmd-i"></i>运行中
          </div>
          <div class="cmd-margin">遇到故障时，重新拉取人员考勤机人员数据</div>
        </el-col>
        <el-col :span="12" class="cmd-col">
          <el-button
            type="primary"
            icon="el-icon-switch-button"
            class="commonBtn cmd-btn"
            @click="onRefresh()"
            >刷新数据显示</el-button
          >
          <div class="cmd-margin">
            <i class="el-icon-refresh cmd-i"></i>运行中
          </div>
          <div class="cmd-margin">刷新拉取人员数据</div>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'zktecoMachine',
  data() {
    return {
      dialogVisible: false,
      dialogTitle: '',
      projectId: '',
      pointId: '',
      machineNO: '',
      projectName: '',
      pointName: '',
      allEmpCount: '',
      pointEmpCount: '',
      downEmpCount: '',
      downFaceCount: '',
      companyId: '',
      companyName: '',
      ncId: '',
      type: '', //类型，非建NC或建筑ZJ
      faceOnJobCount: '',
    }
  },
  created() {},
  methods: {
    handleClose() {
      this.dialogVisible = false
    },
    showYfDetail(rows, type) {
      this.type = type
      if (type === 'NC') {
        this.companyId = rows.companyId
        this.pointId = rows.pointId
        this.machineNO = rows.machineNo
        this.companyName = rows.companyName
        this.ncId = rows.id
        this.gethardwareworkpointNC(rows.companyId, rows.machineNo, rows.id)
      } else {
        this.projectId = rows.projectId
        this.pointId = rows.pointId
        this.machineNO = rows.machineNo
        this.projectName = rows.projectName
        this.getHardwareWorkpoint(rows.projectId, rows.pointId, rows.machineNo)
      }
      this.onRefresh()
      this.dialogTitle = '设备信息'
      this.dialogVisible = true
    },
    getHardwareWorkpoint(projectId, pointId, sn) {
      this.axios({
        method: 'post',
        url: 'api-att/getHardwareWorkpoint',
        data: {
          projectId: projectId,
          projectPoint: pointId,
          sn: sn,
        },
      })
        .then((res) => {
          this.pointName = res.data.result.pointName
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取数据失败',
            type: 'error',
          })
        })
    },
    getHardwareEmpsCount(projectId, pointId, sn) {
      this.axios({
        method: 'post',
        url: 'api-att/getHardwareEmpsCount',
        data: {
          projectId: projectId,
          projectPoint: pointId,
          sn: sn,
        },
      })
        .then((res) => {
          // this.pointName = res.data.result.pointName;
          // this.companyName = res.data.result.companyName;
          // this.machineNO = res.data.result.machineNO;
          this.allEmpCount = res.data.allCount
          this.pointEmpCount = res.data.pointCount
          this.downEmpCount = res.data.count
          this.downFaceCount = res.data.faceCount
          this.faceOnJobCount = res.data.faceOnJobCount
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取数据失败',
            type: 'error',
          })
        })
    },
    gethardwareworkpointNC(companyId, sn, id) {
      this.axios({
        method: 'post',
        url: 'api-att/nc/gethardwareworkpoint',
        data: {
          companyId: companyId,
          sn: sn,
          id: id,
        },
      })
        .then((res) => {
          this.pointName = res.data.result.pointName
          this.companyName = res.data.result.companyName
          this.machineNO = res.data.result.machineNO
          this.allEmpCount = res.data.result.allCount
          this.pointEmpCount = res.data.result.pointCount
          this.downEmpCount = res.data.result.count
          this.downFaceCount = res.data.result.authCode
          // this.faceOnJobCount = res.data.result.faceOnJobCount;
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取数据失败',
            type: 'error',
          })
        })
    },
    onRestDownEmp() {
      if ('NC' === this.type) {
        this.resetmachineemp()
      } else {
        this.zkResetEmpMark()
      }
    },
    //建筑数据重置
    zkResetEmpMark() {
      this.axios({
        method: 'post',
        url: 'api-att/ResetMachineEmp',
        data: {
          sn: this.machineNO,
          projectId: this.projectId,
          projectPoint: this.pointId,
        },
      })
        .then((res) => {
          this.$message({
            message: '请求成功',
            type: 'success',
          })
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '请求失败',
            type: 'error',
          })
        })
    },
    //非建数据重置
    resetmachineemp() {
      this.axios({
        method: 'post',
        url: 'api-att/nc/resetmachineemp',
        data: {
          companyId: this.companyId,
          projectPoint: this.pointId,
          sn: this.machineNO,
        },
      })
        .then((res) => {
          this.$message({
            message: '请求成功',
            type: 'success',
          })
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '请求失败',
            type: 'error',
          })
        })
    },

    onRefresh() {
      if ('NC' === this.type) {
        this.gethardwareworkpointNC(this.companyId, this.machineNO, this.ncId)
      } else {
        this.getHardwareEmpsCount(this.projectId, this.pointId, this.machineNO)
      }
    },
  },
}
</script>

<style scoped>
.el-col {
  border-radius: 0px;
  border: 1px #dddddd solid;
  height: 36px;
  line-height: 36px;
  background-color: #edeff1;
  padding-left: 10px;
}
@media screen and (max-height: 768px) {
  .el-dialog__body {
    max-height: 535px;
  }
}
/*.el-dialog__body {*/
/*    height: 535px;*/
/*    overflow-y: auto;*/
/*}*/
.cmd-col {
  border: none;
  height: 180px;
  line-height: 20px;
  background-color: #ebebeb;
  text-align: center;
  padding: 10px;
}
.cmd-btn {
  width: 220px;
  height: 60px;
}
.cmd-i {
  font-size: 32px;
  vertical-align: middle;
  margin-right: 10px;
  color: #389531;
}
.cmd-margin {
  margin-top: 10px;
}
</style>
